package com.pethome.pet.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pethome.pet.domain.Disease;
import com.pethome.pet.mapper.DiseaseMapper;
import com.pethome.pet.service.IDiseaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 常见疾病Service业务层处理
 * 
 * @author 胡继承
 * @date 2024-09-02
 */
@Service
public class DiseaseServiceImpl extends ServiceImpl<DiseaseMapper,Disease> implements IDiseaseService
{
    @Autowired
    private DiseaseMapper diseaseMapper;

    /**
     * 增加查询后疾病信息的查询次数
     * @param disease 要修改的疾病信息
     * @return Boolean
     */
    @Override
    public Boolean plussSearchCount(Disease disease) {
        Long count = disease.getDiseaseSearchCount()+1;
        disease.setDiseaseSearchCount(count);
        return diseaseMapper.updateDisease(disease)==1;
    }

    /**
     * 获取前5条 搜索次数最多的数据
     * @return list
     */
    @Override
    public List<Disease> getTop5() {
        QueryWrapper<Disease> qw = new QueryWrapper<Disease>();
        qw.orderByDesc("disease_search_count");
        qw.last("LIMIT 5");
        List<Disease> list = this.list(qw);
        return list;
    }

    /**
     * 查询常见疾病
     * 
     * @param diseaseId 常见疾病主键
     * @return 常见疾病
     */
    @Override
    public Disease selectDiseaseByDiseaseId(Long diseaseId)
    {
        return diseaseMapper.selectDiseaseByDiseaseId(diseaseId);
    }

    /**
     * 查询常见疾病列表
     * 
     * @param disease 常见疾病
     * @return 常见疾病
     */
    @Override
    public List<Disease> selectDiseaseList(Disease disease)
    {
        return diseaseMapper.selectDiseaseList(disease);
    }

    /**
     * 新增常见疾病
     * 
     * @param disease 常见疾病
     * @return 结果
     */
    @Override
    public int insertDisease(Disease disease)
    {
        return diseaseMapper.insertDisease(disease);
    }

    /**
     * 修改常见疾病
     * 
     * @param disease 常见疾病
     * @return 结果
     */
    @Override
    public int updateDisease(Disease disease)
    {
        return diseaseMapper.updateDisease(disease);
    }

    /**
     * 批量删除常见疾病
     * 
     * @param diseaseIds 需要删除的常见疾病主键
     * @return 结果
     */
    @Override
    public int deleteDiseaseByDiseaseIds(Long[] diseaseIds)
    {
        return diseaseMapper.deleteDiseaseByDiseaseIds(diseaseIds);
    }

    /**
     * 删除常见疾病信息
     * 
     * @param diseaseId 常见疾病主键
     * @return 结果
     */
    @Override
    public int deleteDiseaseByDiseaseId(Long diseaseId)
    {
        return diseaseMapper.deleteDiseaseByDiseaseId(diseaseId);
    }
}
